package vivo;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
 * @Classname Solution_2
 * @Author happytaohaha
 * @Date 2020/3/8
 * @Description 找最小质数，找到比十大的是错误的
 */
public class Solution_2 {
    public static int solution(int n) {
        List<Integer> list = new ArrayList();
        int flag = 0;
        while (n > 1 && flag >= 0) {
            for (int i = 2; i <= n / 2; i++) {
                if (n / i * i == n) {
                    n = n / i;
                    list.add(i);
                    flag = 1;
                    break;
                }
            }
            if (flag != 1) {
                flag = -1;
            } else {
                flag = 0;
            }
        }
        if (n > 10) {
            return -1;
        } else {
            list.add(n);
        }
        Integer[] a;
        a = list.toArray(new Integer[0]);
        Arrays.sort(a);
        int sum = 0;
        for (int i = 0; i < a.length; i++) {
            if (i < a.length - 2 && a[i] * a[i + 1]*a[i + 2]< 10) {
                sum = sum * 10 + a[i] * a[i + 1]*a[i + 2];
                i = i+2;
            } else if (i < a.length - 1 && a[i] * a[i + 1] < 10) {
                sum = sum * 10 + a[i] * a[i + 1];
                i++;
            } else {
                sum = sum * 10 + a[i];
            }
        }
        return sum;
    }

    public static void main(String[] args) {
        System.out.println(solution(7));
    }
}
